home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / mus / edit / amisox_wav.lha / avg.c < prev    next >
C/C++ Source or Header  |  1992-03-27  |  2KB  |  127 lines

  1.  
  2. /*
  3.  * July 5, 1991
  4.  * Copyright 1991 Lance Norskog And Sundry Contributors
  5.  * This source code is freely redistributable and may be used for
  6.  * any purpose.  This copyright notice must be maintained. 
  7.  * Lance Norskog And Sundry Contributors are not responsible for 
  8.  * the consequences of using this software.
  9.  */
  10.  
  11. /*
  12.  * Sound Tools stereo/quad -> mono mixdown effect file.
  13.  *
  14.  * Does not mix up to more channels.
  15.  *
  16.  * What's in a center channel?
  17.  */
  18.  
  19. #include "st.h"
  20.  
  21. /*
  22.  * Process options
  23.  */
  24. avg_getopts(effp, n, argv) 
  25. eff_t effp;
  26. int n;
  27. char **argv;
  28. {
  29.     if (n)
  30.         fail("Averaging effect takes no options.");
  31. }
  32.  
  33. /*
  34.  * Start processing
  35.  */
  36. void
  37. avg_start(effp)
  38. eff_t effp;
  39. {
  40.     switch (effp->outinfo.channels) {
  41.         case 1: switch (effp->ininfo.channels) {
  42.             case 2: 
  43.             case 4:
  44.                 return;
  45.         }
  46.         case 2: switch (effp->ininfo.channels) {
  47.             case 4:
  48.                 return;
  49.         }
  50.     }
  51.     fail("Can't average %d channels into %d channels",
  52.         effp->ininfo.channels, effp->outinfo.channels);
  53. }
  54.  
  55. /*
  56.  * Process either isamp or osamp samples, whichever is smaller.
  57.  */
  58.  
  59. avg_flow(effp, ibuf, obuf, isamp, osamp)
  60. eff_t effp;
  61. long *ibuf, *obuf;
  62. int *isamp, *osamp;
  63. {
  64.     int len, done;
  65.     
  66.     switch (effp->outinfo.channels) {
  67.         case 1: switch (effp->ininfo.channels) {
  68.             case 2:
  69.                 len = ((*isamp/2 > *osamp) ? *osamp : *isamp/2);
  70.                 for(done = 0; done < len; done++) {
  71.                     *obuf++ = ibuf[0]/2 + ibuf[1]/2;
  72.                     ibuf += 2;
  73.                 }
  74.                 *isamp = len * 2;
  75.                 *osamp = len;
  76.                 break;
  77.             case 4:
  78.                 len = ((*isamp/4 > *osamp) ? *osamp : *isamp/4);
  79.                 for(done = 0; done < len; done++) {
  80.                     *obuf++ = ibuf[0]/4 + ibuf[1]/4 +
  81.                         ibuf[2]/4 + ibuf[3]/4;
  82.                     ibuf += 4;
  83.                 }
  84.                 *isamp = len * 4;
  85.                 *osamp = len;
  86.                 break;
  87.                 
  88.         }
  89.         break;
  90.         case 2: switch (effp->ininfo.channels) {
  91.             /*
  92.              * After careful inspection of CSOUND source code,
  93.              * I'm mildly sure the order is:
  94.              *     front-left, front-right, rear-left, rear-right
  95.              */
  96.             case 4:
  97.                 len = ((*isamp/2 > *osamp) ? *osamp : *isamp/2);
  98.                 len &= ~1;
  99.                 for(done = 0; done < len; done++) {
  100.                     obuf[0] = ibuf[0]/2 + ibuf[2]/2;
  101.                     obuf[1] = ibuf[1]/2 + ibuf[3]/2;
  102.                     ibuf += 4;
  103.                     obuf += 2;
  104.                 }
  105.                 *isamp = len * 2;
  106.                 *osamp = len;
  107.                 break;
  108.         }
  109.     }
  110. }
  111.  
  112. /*
  113.  * Do anything required when you stop reading samples.  
  114.  * Don't close input file! 
  115.  *
  116.  * Should have statistics on right, left, and output amplitudes.
  117.  */
  118. avg_stop(effp)
  119. eff_t effp;
  120. {
  121.     /* nothing to do */
  122. }
  123.  
  124.  
  125.  
  126.  
  127.